home *** CD-ROM | disk | FTP | other *** search
- /*************************************************
- * *
- * E! for Windows *
- * (c) - MainSOft sarl - 1995 *
- * *
- * PRJPICK Extension DLL - version 1.0 *
- * *
- * Display picklist of Project files. *
- * *
- *************************************************/
-
- /*
- PRJPICK is an Extension DLL allowing to display your project
- files as specified in EW.PRJ and to select a file for
- editing. It works even if your Project file contains
- file specifications with wildcards.
-
- PRJPICK needs a new function of the E! API: EWGetPrjName.
- This function exists only since version E! version 2.02.
-
- PRJPICK only exports an EWExecute function. So you just have
- to assign this DLL to a key or to a User Menu item to
- install it after copying PRJPICK.EWD to your \EW\USER
- directory.
-
- Enjoy!
-
- Patrick Philippot
- 08-02-95
- */
-
- #include <windows.h>
- #include "ewapi2.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <dos.h>
-
-
- #define id_ListBox 100
-
- char PrjName[_MAX_PATH];
- char FileName[_MAX_PATH];
- HWND ListBoxHandle, OkBtHandle;
- HANDLE hInst;
-
- struct _find_t c_file;
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
- char buffer[_MAX_PATH];
-
- char szError[] = "Error!";
-
-
- BOOL CALLBACK ChoiceDlg(HWND hwndDlg, UINT Message, WPARAM wParam, LPARAM lParam)
- // This is the dialog procedure managing the list of files
- {
- int Index;
- FILE* Prj;
-
- switch (Message)
- {
- case WM_INITDIALOG:
- // Get handle of Listbox
- ListBoxHandle = GetDlgItem(hwndDlg, id_ListBox);
- OkBtHandle = GetDlgItem(hwndDlg, IDOK);
- EnableWindow(OkBtHandle, FALSE);
- SetFocus(ListBoxHandle);
- // Open Project file
- if ((Prj = fopen(PrjName, "r")) == NULL)
- {
- EWMessageBox(GetFocus(),
- "Couldn't open Project File.",
- szError,
- MB_OK | MB_ICONEXCLAMATION);
-
- return TRUE;
- }
- // Read lines and add filename to Listbox
- while (fgets(FileName, sizeof(FileName), Prj))
- {
- int len = _fstrlen(FileName);
-
- // Remove /n included by fgets
- if ((len > 0) && (FileName[len - 1] == '\n'))
- FileName[len - 1] = 0;
-
- if (_fstrchr(FileName, '=') == NULL)
- {
- if ((_fstrchr(FileName, '*') == NULL) && (_fstrchr(FileName, '?') == NULL))
- // The filename contains no wildcards
- {
- AnsiLower(FileName);
- SendMessage(ListBoxHandle, LB_ADDSTRING, 0, (LPARAM) (char FAR*) FileName);
- }
- else
- {
- _splitpath(FileName, drive, dir, fname, ext);
-
- if (dir[0] == 0)
- // The filename doesn't contain a path. Use the path of the project file
- {
- _splitpath(PrjName, drive, dir, fname, ext);
- _fstrcpy(fname, FileName);
- _fstrcat(_fstrcat(_fstrcpy(FileName, drive), dir), fname);
- }
-
- if (_dos_findfirst(FileName, _A_RDONLY, &c_file) == 0)
- {
- // Enumerate files
- _fstrcat(_fstrcat(_fstrcpy(buffer, drive), dir), c_file.name);
- AnsiLower(buffer);
- SendMessage(ListBoxHandle, LB_ADDSTRING, 0, (LPARAM) (char FAR*) buffer);
- while (_dos_findnext(&c_file) == 0)
- {
- _fstrcat(_fstrcat(_fstrcpy(buffer, drive), dir), c_file.name);
- AnsiLower(buffer);
- SendMessage(ListBoxHandle, LB_ADDSTRING, 0, (LPARAM) (char FAR*) buffer);
- }
- }
- }
- }
- }
- fclose(Prj);
- return TRUE;
-
- case WM_COMMAND:
- switch (wParam)
- {
- case id_ListBox:
- if (HIWORD(lParam) != LBN_DBLCLK)
- // A double_click is processed as the IDOK command
- {
- if (HIWORD(lParam) == LBN_SELCHANGE)
- {
- EnableWindow(OkBtHandle, TRUE);
- return TRUE;
- }
- else
- return FALSE;
- }
- case IDOK:
- Index = SendMessage(ListBoxHandle, LB_GETCURSEL, 0, 0);
- if (Index != LB_ERR)
- // A Project File is currently selected
- {
- SendMessage(ListBoxHandle, LB_GETTEXT, Index, (LPARAM) (char FAR*) FileName);
- EWEditFile(FileName);
- }
- else
- {
- MessageBeep(0);
- EWMessageBox(GetFocus(),
- "No Project File Selected.",
- szError,
- MB_OK | MB_ICONEXCLAMATION);
- };
- case IDCANCEL:
- EndDialog(hwndDlg, IDCANCEL);
- return TRUE;
- }
-
- default:
- return FALSE;
- }
- }
-
- int FAR PASCAL EWExecute(unsigned int RoutineId)
- {
- DLGPROC ChoiceProc;
- UINT nVersion = EWGetVersion();
-
- // Check version number
- if ((HIBYTE(nVersion) < 2) || ((HIBYTE(nVersion) == 2) && (LOBYTE(nVersion) < 2)))
- {
- EWMessageBox(GetFocus(),
- "This Extension DLL needs E! version 2.02 or newer.",
- szError,
- MB_OK | MB_ICONEXCLAMATION);
- return(ewerr_EXTFAILED);
- }
-
- if (EWGetPrjName(PrjName) == 0)
- {
- ChoiceProc = (DLGPROC) MakeProcInstance(ChoiceDlg, hInst);
- DialogBox(hInst, "Picklist", GetFocus(), ChoiceProc);
- FreeProcInstance((FARPROC) ChoiceProc);
- return 0;
- }
- else
- return(ewerr_EXTFAILED);
- }
-
-
- int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
- LPSTR lpszCmdLine)
- {
- hInst = hInstance;
- if (wHeapSize > 0)
- UnlockData (0) ;
- return 1;
- }
-
-